package com.nny.demo141;

import com.nny.demo513.Emp;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

public class TestSet {
    public void addEmp(Set<Emp> set, Emp emp) {
        set.add(emp);
    }
    public void findAllEmp(Set<Emp> set) {
        for (Emp emp : set) {
            System.out.println(emp);
        }
    }
    public Emp findEmpName(Set<Emp> set, String name) {
        for (Emp emp : set) {
            if (emp.getName().equals(name)) {
                return emp;
            }
        }
        return null;
    }
    public void deleteNumber(Set<Emp> set, String number) {
        Iterator<Emp> iterator = set.iterator();
        while (((Iterator<?>) iterator).hasNext()) {
            Emp emp = iterator.next();
            if (emp.getNumber().equals(number)) {
                iterator.remove();
                return;
            }
        }
    }
    public Emp findEmpNumber(Set<Emp> set, String number) {
        for (Emp emp : set) {
            if (emp.getNumber().equals(number)) {
                return emp;
            }
        }
        return null;
    }
    public static void main(String[] args) {
        Emp emp1 = new Emp("1001", "小乔", "19");
        Emp emp2 = new Emp("1002", "大乔", "21");
        Set<Emp> set = new HashSet<>();
        set.add(emp1);
        set.add(emp2);
        for (Emp emp : set) {
            System.out.println(emp);
        }
        Scanner scanner = new Scanner(System.in);
        String ename = scanner.next();
        for (Emp emp : set) {
            if (ename.equals(emp.getName())) {
                System.out.println(emp);
            }
        }
    }

    public void updateEmpAge(Set<Emp> empSet, Emp updateEmp) {

    }
}